package com.example.demo.ServiceImpl.User;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.Bean.R;
import com.example.demo.Entity.Login.LogInBackUser;
import com.example.demo.Entity.User.User;
import com.example.demo.Mapper.User.UserMapper;
import com.example.demo.Service.User.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Wu
 * @since 2024-03-22 09:12:56
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public R LogInBack(LogInBackUser user) {
        LambdaQueryWrapper<User>userLambdaQueryWrapper= Wrappers.lambdaQuery();
        userLambdaQueryWrapper.eq(User::getUsername,user.getUsername());
        User user1=this.getOne(userLambdaQueryWrapper);
        if(user1==null){
            return R.error();
        }
        if(Objects.equals(user.getPassword(),user1.getPassword())){
            return R.ok().put("token",user1.getId());
        }else{
            return R.error();
        }
    }
}
